withCriteria

用途

允许闭包内执行criteria,参考createCriteria方法。

举例

def results = Book.withCriteria {
    def now = new Date()
    between('releaseDate', now-7, now)
    like('title', '%Groovy%')
}

描述

withCriteria方法允许在其内部定义Criteria,用于HibernateCriteriaBuilder的参数可以作为第一个参数被传入:

def book = Book.withCriteria(uniqueResult:true) {
    def now = new Date()
    between('releaseDate', now-7, now)
    like('title', '%Groovy%')
}

参数: